package persistencia;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import modeloDatos.Alumno;
import modeloDatos.AlumnoGrupo;
import modeloDatos.AlumnosVistaReducida;
import modeloDatos.Curso;
import modeloDatos.GrupoVistaReducida;
import modeloDatos.RelacionConGrupo;


public class DAOAlumnos {
	
	private Connection conn;
	
	public DAOAlumnos(){
	}
    	
	public void finalize(){
		ConnectionManager.getInstance().checkIn(conn);
    }
	
	public List<AlumnosVistaReducida> recuperarAlumnos(){
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT * FROM alumnos";
        ResultSet result = null;
        List<AlumnosVistaReducida> alumnos = new LinkedList<AlumnosVistaReducida>();
		try {
			stmt = conn.prepareStatement(sql);
			result = stmt.executeQuery();
			while (result.next()) {
				AlumnosVistaReducida aVR = new AlumnosVistaReducida(result.getInt("idAlumno"), result.getString("Nombre"), result.getString("Apellidos"), result.getString("nif"));
				alumnos.add(aVR);
			}
		} catch (SQLException ex) {
			System.out.println("Message: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("ErrorCode: " + ex.getErrorCode());
		} finally {
			finalize();
			try {
				if (result != null) {
					result.close();
				}
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException ex) {
			}
		}
		return alumnos;
	}
	
	public List<AlumnosVistaReducida> recuperarAlumnosActivos(){
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT DISTINCT a.idAlumno, a.nombre, a.apellidos, a.nif FROM alumnos a, alumnogrupo ag WHERE a.idAlumno=ag.idAlumno AND ag.idEstadoAlumno<>6";
        ResultSet result = null;
        List<AlumnosVistaReducida> alumnos = new LinkedList<AlumnosVistaReducida>();
		try {
			stmt = conn.prepareStatement(sql);
			result = stmt.executeQuery();
			while (result.next()) {
				AlumnosVistaReducida aVR = new AlumnosVistaReducida(result.getInt("idAlumno"), result.getString("nombre"), result.getString("apellidos"), result.getString("nif"));
				alumnos.add(aVR);
			}
		} catch (SQLException ex) {
			System.out.println("Message: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("ErrorCode: " + ex.getErrorCode());
		} finally {
			finalize();
			try {
				if (result != null) {
					result.close();
				}
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException ex) {
			}
		}
		return alumnos;
	}
	
	public Alumno recuperarAlumno(Integer idAlumno){
		Alumno a = null;
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT * FROM alumnos WHERE idAlumno = ?";
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, idAlumno);
			ResultSet result = stmt.executeQuery();
			if (result.next()) {
				a = new Alumno(result.getInt("idAlumno"), result.getString("nombre"), result.getString("apellidos"), result.getDate("fechaNacimiento"), result.getInt("telefonoFijo"), result.getInt("telefonoMovil"), result.getString("email"), result.getString("direccion"), result.getString("localidad"), result.getString("provincia"), result.getInt("cp"), result.getString("numeroSS"), result.getString("nif"), result.getString("sexo"), result.getString("observaciones"), getEstudio(result.getInt("idEstudios")), result.getBoolean("preferencia"), result.getDate("fechaAlta"), result.getString("discapacidad"), result.getString("usuario"), result.getString("clave"));
			}
		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
			}
		}
		return a;
	}
	
	public String getEstudio(Integer idEstudios){
		String res = "";
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT * FROM estudios WHERE idEstudios = ?";
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, idEstudios);
			ResultSet result = stmt.executeQuery();
			if (result.next()) {
				res = result.getString("descripcion");
			}
		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
			}
		}
		return res;
	}
	
	public List<String> recuperarEstudios(){
		List<String> res = new LinkedList<String>();
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT * FROM estudios";
		try {
			stmt = conn.prepareStatement(sql);
			ResultSet result = stmt.executeQuery();
			while (result.next()) {
				res.add(result.getString("descripcion"));
			}
		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
			}
		}
		return res;
	}
	
	public List<RelacionConGrupo> relacionesAlumno(Integer idAlumno){
		List<RelacionConGrupo> res = new LinkedList<RelacionConGrupo>();
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT ag.idAlumno, ag.idGrupo, g.numeroGrupo, ea.descripcion AS descA, sl.descripcion AS descSL, c.descripcion FROM alumnogrupo ag, grupos g, cursos c, estadoalumno ea, situacionlaboral sl WHERE ag.idEstadoAlumno=ea.idEstadoAlumno AND ag.idGrupo=g.idGrupo AND ag.idSituacionLaboral=sl.idSituacionLaboral AND g.idCurso=c.idCurso AND ag.idAlumno=?";
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, idAlumno);
			ResultSet result = stmt.executeQuery();
			while (result.next()) {
				RelacionConGrupo rAG = new RelacionConGrupo(result.getInt("idAlumno"), result.getInt("idGrupo"), result.getString("numeroGrupo"), result.getString("descripcion"), result.getString("descA"), result.getString("descSL"));
				res.add(rAG);
			}
		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
			}
		}
		return res;
	}
	
	public boolean nuevoAlumno(Alumno alumnoNuevo){
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "INSERT INTO alumnos(nombre,apellidos,fechaNacimiento,telefonoFijo,telefonoMovil,email,direccion,localidad,provincia,cp,numeroSS,nif,sexo,observaciones,idEstudios,preferencia,fechaAlta,discapacidad) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,(SELECT idEstudios FROM estudios WHERE descripcion=?),?,?,?)";
		try {
			stmt = conn.prepareStatement(sql);
			
			stmt.setString(1, alumnoNuevo.getNombre());
			stmt.setString(2, alumnoNuevo.getApellidos());
			stmt.setDate(3, alumnoNuevo.getFechaNacimiento());
			stmt.setInt(4, alumnoNuevo.getTelefonoFijo());
			stmt.setInt(5, alumnoNuevo.getTelefonoMovil());
			stmt.setString(6, alumnoNuevo.getEmail());
			stmt.setString(7, alumnoNuevo.getDireccion());
			stmt.setString(8, alumnoNuevo.getLocalidad());
			stmt.setString(9, alumnoNuevo.getProvincia());
			stmt.setInt(10, alumnoNuevo.getCp());
			stmt.setString(11, alumnoNuevo.getNumeroSS());
			stmt.setString(12, alumnoNuevo.getNif());
			stmt.setString(13, alumnoNuevo.getSexo());
			stmt.setString(14, alumnoNuevo.getObservaciones());
			stmt.setString(15, alumnoNuevo.getEstudios());
			stmt.setBoolean(16, alumnoNuevo.getPreferencia());
			stmt.setDate(17, new Date(System.currentTimeMillis()));
			stmt.setString(18, alumnoNuevo.getDiscapacidad());
			
			stmt.execute();
		} catch (SQLException ex) {
			System.out.println("Message: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("ErrorCode: " + ex.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException ex) {
			}
		}
		return true;
	}
	
	public boolean modificarAlumno(Alumno alumnoNuevo){
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "UPDATE alumnos SET nombre=?,apellidos=?,fechaNacimiento=?,telefonoFijo=?,telefonoMovil=?,email=?,direccion=?,localidad=?,provincia=?,cp=?,numeroSS=?,nif=?,sexo=?,observaciones=?,idEstudios=(SELECT idEstudios FROM estudios WHERE descripcion=?),preferencia=?,fechaAlta=?,discapacidad=?,usuario=?,clave=? WHERE idAlumno=?";
		try {
			stmt = conn.prepareStatement(sql);
			
			stmt.setString(1, alumnoNuevo.getNombre());
			stmt.setString(2, alumnoNuevo.getApellidos());
			stmt.setDate(3, alumnoNuevo.getFechaNacimiento());
			stmt.setInt(4, alumnoNuevo.getTelefonoFijo());
			stmt.setInt(5, alumnoNuevo.getTelefonoMovil());
			stmt.setString(6, alumnoNuevo.getEmail());
			stmt.setString(7, alumnoNuevo.getDireccion());
			stmt.setString(8, alumnoNuevo.getLocalidad());
			stmt.setString(9, alumnoNuevo.getProvincia());
			stmt.setInt(10, alumnoNuevo.getCp());
			stmt.setString(11, alumnoNuevo.getNumeroSS());
			stmt.setString(12, alumnoNuevo.getNif());
			stmt.setString(13, alumnoNuevo.getSexo());
			stmt.setString(14, alumnoNuevo.getObservaciones());
			stmt.setString(15, alumnoNuevo.getEstudios());
			stmt.setBoolean(16, alumnoNuevo.getPreferencia());
			stmt.setDate(17, new Date(System.currentTimeMillis()));
			stmt.setString(18, alumnoNuevo.getDiscapacidad());
			stmt.setString(19,alumnoNuevo.getUsuario());
			stmt.setString(20, alumnoNuevo.getClave());
			stmt.setInt(21, alumnoNuevo.getIdAlumno());
			stmt.execute();
		} catch (SQLException ex) {
			System.out.println("Message: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("ErrorCode: " + ex.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException ex) {
			}
		}
		return true;
	}
	
	public AlumnoGrupo recuperarAlumnoGrupo(Integer idAlumno, Integer idGrupo){
		AlumnoGrupo ag = null;
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT * FROM alumnogrupo WHERE idAlumno = ? AND idGrupo = ?";
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, idAlumno);
			stmt.setInt(2, idGrupo);
			ResultSet result = stmt.executeQuery();
			if (result.next()) {
				ag = new AlumnoGrupo(result.getInt("idAlumno"),result.getInt("idGrupo"),recuperarEstadoAlumno(result.getInt("idEstadoAlumno")),recuperarSituacionLaboral(result.getInt("idSituacionLaboral")),
						result.getInt("idClienteEmpresa"),result.getDouble("evaluacion"),result.getString("incidencias"),result.getBoolean("docSolicitud"),
						result.getBoolean("docpropuestaprestacionservicios"),result.getBoolean("docconvenio"),result.getBoolean("docestudios"),
						result.getBoolean("docSS"),result.getBoolean("docDNI"),
						result.getBoolean("docNominaPrevia"),result.getBoolean("docNominaInicio"),result.getBoolean("docSelloAutonomo"),
						result.getBoolean("docEscrituraEmpresa"),result.getBoolean("docTarjetaDesempleo"),result.getBoolean("docEvaluacionAlumno"),
						result.getBoolean("docCuestionarioCalidad"),result.getBoolean("recepcionMaterial"),result.getBoolean("expedicionTitulo"),
						result.getString("lugarEntregaTitulo"),result.getDate("fechaEnviado"),result.getDate("fechaRecepcion"));
			}
		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
			}
		}
		return ag;
	}
	
	public String recuperarEstadoAlumno(Integer idEstadoAlumno){
		String res = "";
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT * FROM estadoalumno WHERE idEstadoAlumno = ?";
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, idEstadoAlumno);
			ResultSet result = stmt.executeQuery();
			if (result.next()) {
				res = result.getString("descripcion");
			}
		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
			}
		}
		return res;
	}
	
	public String recuperarSituacionLaboral(Integer idSituacionLaboral){
		String res = "";
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT * FROM situacionlaboral WHERE idSituacionLaboral = ?";
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, idSituacionLaboral);
			ResultSet result = stmt.executeQuery();
			if (result.next()) {
				res = result.getString("descripcion");
			}
		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
			}
		}
		return res;
	}
	
	public GrupoVistaReducida recuperaGrupoVistaReducida(Integer idGrupo){
		conn = ConnectionManager.getInstance().checkOut();
        ResultSet result = null;
        GrupoVistaReducida grupo = null;
        PreparedStatement stmt = null;
        String sql = "SELECT g.idGrupo, g.idCurso, g.numeroGrupo, g.numeroAlumnosMax, g.numeroAlumnosActuales, " +
        		"sg.descripcion as situacion FROM grupos g, situacionesgrupos sg WHERE g.idGrupo = ? AND g.idSituacion = sg.idSituacion";
        try{
        	stmt = conn.prepareStatement(sql);
        	stmt.setInt(1, idGrupo);
        	result = stmt.executeQuery();
        	if(result.next()){
        		GrupoVistaReducida grupoAux = new GrupoVistaReducida(result.getInt("idGrupo"), result.getString("idCurso"),
        				result.getString("numeroGrupo"), result.getInt("numeroAlumnosMax"), result.getInt("numeroAlumnosActuales"),
        				result.getString("situacion"));
        		grupo = grupoAux;
        		
        		
        	}    	
        	}catch(SQLException ex){
            	System.out.println("Message: " + ex.getMessage());
    			System.out.println("SQLState: " + ex.getSQLState());
    			System.out.println("ErrorCode: " + ex.getErrorCode());
            }finally{
            	finalize();
            	try{
            		if(result != null){
            			result.close();
            		}
            		if(stmt != null){
            			stmt.close();
            		}
            	}catch(SQLException ex){
            	}
            }
        return grupo;
	}
	
	public String recuperaNombreCliente(Integer idClienteEmpresa){
		conn = ConnectionManager.getInstance().checkOut();
        ResultSet result = null;
        String res = "";
        PreparedStatement stmt = null;
        String sql = "SELECT * FROM clientes WHERE idClienteEmpresa=?";
        try{
        	stmt = conn.prepareStatement(sql);
        	stmt.setInt(1, idClienteEmpresa);
        	result = stmt.executeQuery();
        	if(result.next()){
        		res = res + result.getString("nombre") + result.getString("apellidos");
        	}    	
        	}catch(SQLException ex){
            	System.out.println("Message: " + ex.getMessage());
    			System.out.println("SQLState: " + ex.getSQLState());
    			System.out.println("ErrorCode: " + ex.getErrorCode());
            }finally{
            	finalize();
            	try{
            		if(result != null){
            			result.close();
            		}
            		if(stmt != null){
            			stmt.close();
            		}
            	}catch(SQLException ex){
            	}
            }
        return res;
	}
	public Curso recuperarCurso(String idCurso){
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "SELECT c.idCurso, c.descripcion, tc.descripcion AS descTipo, rc.descripcion AS descRequisito, " +
				"c.horas, c.observaciones, c.especialidad, c.entidad " +
				"FROM cursos c, tiposcursos tc, requisitoscursos rc " +
				"WHERE c.idCurso=? AND c.idTipo = tc.idTipo AND c.idRequisitos = rc.idRequisitos";
        ResultSet result = null;
        Curso res = null;
        try{
        	stmt = conn.prepareStatement(sql);
        	stmt.setString(1, idCurso);
        	result = stmt.executeQuery();
        	if (result.next()) {
        		res = new Curso(result.getString("idCurso"), result.getString("descripcion"), result.getInt("horas"), 
        				result.getString("especialidad"), result.getString("entidad"), result.getString("observaciones"),
        				result.getString("descTipo"), result.getString("descRequisito"));
        	}
        }catch(SQLException ex){
        	System.out.println("Message: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("ErrorCode: " + ex.getErrorCode());
        }finally{
        	finalize();
        	try{
        		if(result != null){
        			result.close();
        		}
        		if(stmt != null){
        			stmt.close();
        		}
        	}catch(SQLException ex){
        	}
        } 
        return res;
	}
	public boolean actualizarAlumnoGrupo(AlumnoGrupo aGM){
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "UPDATE alumnogrupo SET idEstadoAlumno=(SELECT idEstadoAlumno FROM estadoalumno WHERE descripcion=?)," +
				"idSituacionLaboral=(SELECT idSituacionLaboral FROM situacionlaboral WHERE descripcion=?)," +
				"idClienteEmpresa=?,evaluacion=?,incidencias=?,docpropuestaprestacionservicios=?," +
				"docconvenio=?,docestudios=?,docDni=?,docSolicitud=?,docSS=?,docNominaPrevia=?," +
				"docNominaInicio=?,docSelloAutonomo=?,docEscrituraEmpresa=?,docTarjetaDesempleo=?," +
				"recepcionMaterial=?,docEvaluacionAlumno=?,docCuestionarioCalidad=?,expedicionTitulo=?," +
				"lugarEntregaTitulo=?,fechaEnviado=?,fechaRecepcion=? WHERE idAlumno=? AND idGrupo=?";
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, aGM.getEstadoAlumno());
			stmt.setString(2, aGM.getSituacionLaboral());
			stmt.setInt(3, aGM.getIdClienteEmpresa());
			stmt.setDouble(4, aGM.getEvaluacion());
			stmt.setString(5, aGM.getIncidencias());
			stmt.setBoolean(6, aGM.getDocpropuestaprestacionservicios());
			stmt.setBoolean(7, aGM.getDocconvenio());
			stmt.setBoolean(8, aGM.getDocestudios());
			stmt.setBoolean(9, aGM.getDocDNI());
			stmt.setBoolean(10, aGM.getDocSolicitud());
			stmt.setBoolean(11, aGM.getDocSS());
			stmt.setBoolean(12, aGM.getDocNominaInicio());
			stmt.setBoolean(13, aGM.getDocNominaPrevia());
			stmt.setBoolean(14, aGM.getDocSelloAutonomo());
			stmt.setBoolean(15, aGM.getDocEscrituraEmpresa());
			stmt.setBoolean(16, aGM.getDocTarjetaDesempleo());
			stmt.setBoolean(17, aGM.getRecepcionMaterial());
			stmt.setBoolean(18, aGM.getDocEvaluacionAlumno());
			stmt.setBoolean(19, aGM.getDocCuestionarioCalidad());
			stmt.setBoolean(20, aGM.getExpedicionTitulo());
			stmt.setString(21, aGM.getLugarEntregaTitulo());
			stmt.setDate(22, aGM.getFechaEnviado());
			stmt.setDate(23, aGM.getFechaRecepcion());
			stmt.setInt(24, aGM.getIdAlumno());
			stmt.setInt(25, aGM.getIdGrupo());
			stmt.execute();
		} catch (SQLException ex) {
			System.out.println("Message: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("ErrorCode: " + ex.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException ex) {
			}
		}
		return true;
	}
	public void actualizaEstadoAlumno(Integer idAlumno, Integer idGrupo, Integer idEstadoAlumno){
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "UPDATE alumnogrupo SET idEstadoAlumno=? WHERE idAlumno=? AND idGrupo=?";
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, idEstadoAlumno);
			stmt.setInt(2, idAlumno);
			stmt.setInt(3, idGrupo);
			stmt.execute();
		} catch (SQLException ex) {
			System.out.println("Message: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("ErrorCode: " + ex.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException ex) {
			}
		}
	}
	
	public boolean deleteAlumno(Integer idAlumno){
		conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "DELETE FROM `alumnos` WHERE idAlumno=?";
		try {
			stmt = conn.prepareStatement(sql);
			
			stmt.setInt(1, idAlumno);
			
			stmt.execute();
		} catch (SQLException ex) {
			System.out.println("Message: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("ErrorCode: " + ex.getErrorCode());
		} finally {
			finalize();
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException ex) {
			}
		}
		return true;
	}
}
